package com.itheima.controller;

import com.itheima.bean.ArticleContext;
import com.itheima.bean.ArticleList;
import com.itheima.bean.FrontArticleVO;
import com.itheima.dto.UserLoginDTO;
import com.itheima.result.R;
import com.itheima.service.IndexService;
import com.itheima.service.SysConfigService;
import com.itheima.service.YddArticleService;
import com.itheima.vo.IndexAllDataVO;
import com.itheima.vo.LoginTokenVO;
import com.itheima.vo.ProfileVO;
import com.itheima.vo.YddArticleShowVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @projectName: kafka
 * @package: com.itheima.controller
 * @className: LoginController
 * @author: Eric
 * @description: TODO
 * @date: 2023/9/20 0:11
 * @version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/index")
@AllArgsConstructor
public class IndexController {
    private final IndexService sysUserService;
    private final SysConfigService sysConfigService;
    private final YddArticleService yddArticleService;

    /**
     * 登录
     *
     * @param userLoginDTO 用户登录d到
     * @return {@link R}
     */
    @PostMapping("/login")
    public R<LoginTokenVO> login(@RequestBody UserLoginDTO userLoginDTO){
        LoginTokenVO userLoginVO = sysUserService.login(userLoginDTO);
        return R.success(userLoginVO);
    }

    /**
     * 获取用户信息
     *
     * @return {@link R}
     */
    @PostMapping("/profile")
    public R<ProfileVO> getUserInfo(){
        ProfileVO profileVO = sysUserService.getUserInfo();
        return R.success(profileVO);
    }

    @GetMapping("/getConfig")
    public R<Map<String,String>> getConfig(){
        Map<String,String> map = sysConfigService.getConfig();
        return R.success(map);
    }

    /**
     * 热门文章
     *
     * @param page  第页
     * @param limit 限制
     * @return {@link R}<{@link FrontArticleVO}>
     */
    @GetMapping("/new")
    public R<FrontArticleVO> topArticles(Integer page, Integer limit){
        FrontArticleVO frontArticleVO = yddArticleService.topArticles(page,limit);
        return R.success(frontArticleVO);
    }

    /**
     * 热门文章
     *
     * @return {@link R}
     */
    @GetMapping("/hot")
    public R<ArticleContext> hotArticles(){
        ArticleContext articleHotList = yddArticleService.selectHotArticles();
        return R.success(articleHotList);
    }

    /**
     * 推荐文章
     *
     * @return {@link R}
     */
    @GetMapping("/recommend")
    public R<ArticleContext> recommendArticles(){
        ArticleContext articleContext = yddArticleService.selectRecommendArticles();
        return R.success(articleContext);
    }

    /**
     * 显示文章
     *
     * @param id id
     * @return {@link R}<{@link YddArticleShowVO}>
     */
    @GetMapping("/show")
    public R<YddArticleShowVO> showArticles(Integer id){
        YddArticleShowVO yddArticleShowVO = yddArticleService.showArticles(id);
        return R.success(yddArticleShowVO);
    }

    /**
     * 文章列表
     *
     * @param page   第页
     * @param limit  限制
     * @param cateid cateid
     * @return {@link R}<{@link ArticleList}>
     */
    @GetMapping("/list")
    public R<ArticleList> articleList(Integer page,Integer limit,Integer cateid){
        ArticleList articleList = yddArticleService.articleList(page,limit,cateid);
        return R.success(articleList);
    }

    /**
     * 索引数据
     *
     * @return {@link R}
     */
    @GetMapping("/index")
    public R indexData(){
        IndexAllDataVO indexAllDataVO = yddArticleService.indexData();
        return R.success(indexAllDataVO);
    }
}
